package com.leyou.item.web;

import com.leyou.common.dto.PageDTO;
import com.leyou.item.dto.SpuDTO;
import com.leyou.item.service.SkuService;
import com.leyou.item.service.SpuDetailService;
import com.leyou.item.service.SpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods")
public class GoodController {

    @Autowired
    private SkuService skuService;

    @Autowired
    private SpuService spuService;

    @Autowired
    private SpuDetailService detailService;

    @GetMapping("/spu/page")
    public ResponseEntity<PageDTO<SpuDTO>> pageQuery(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "rows", defaultValue = "5") Integer rows,
            @RequestParam(value = "id", required = false) Long id,
            @RequestParam(value = "brandId", required = false) Long bid,
            @RequestParam(value = "categoryId", required = false) Long cid,
            @RequestParam(value = "saleable", required = false) Boolean saleable) {

        return ResponseEntity.ok(this.spuService.pageQuery(page, rows, id, bid, cid, saleable));
    }

    @PutMapping("/saleable")
    public ResponseEntity<Void> modifySaleable(
            @RequestParam("id") Long spuId,
            @RequestParam("saleable") Boolean saleable) {

        this.spuService.modifySaleable(spuId, saleable);

        return ResponseEntity.ok().build();
    }
}
